
package com.zuul.filter;
import com.xcc.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import javax.sound.sampled.Port;
import javax.validation.Valid;


/**
 * @author frosty
 * @description
 * @date 2019-11-13 13:16:50
 */



/*不知道为什么 redisUtil 没有注入进来 手动注入一次*/

//@DependsOn("redisTemplate")
//@Component
public class ZuulConfig {
    @Autowired(required = false)
     private RedisTemplate redisTemplate;
    @Autowired(required = false)
    private    RedisUtil redisUtil;

  // @Bean
  //@DependsOn("redisTemplate")*/
    public RedisUtil redisUtil(){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //如果不配置Serializer，那么存储的时候缺省使用String，如果用User类型存储，那么会提示错误User can't cast to String！
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        // 开启事务
        redisTemplate.setEnableTransactionSupport(true);

           if(redisUtil!=null){
               return  null;
        }
        RedisUtil redisUtil=new RedisUtil();
        redisUtil.setRedisTemplate(redisTemplate);
        return redisUtil;
    }


}

